<?php
include("admin_check.php");
include_once("../function.php");
include_once("action.php");
include_once("../class/system_class.php");
include_once("../alisms/sendSms.php");
include_once ("../bonus.php");

$_system=new system_class();
$systemparameters=$_system->system_information(1);

$send = new alisendsms();

session_start();
header("Content-Type: text/html;charset=utf-8");
checkqx(2,9);
#搜索会员
if ($_POST['Search']){
	$SearchContent=$_POST['SearchContent'];
	$TimeStart=$_POST['TimeStart'];
	$TimeEnd=$_POST['TimeEnd'];
	$SearchType=$_POST['SearchType'];
	if ($TimeStart!=NULL){
		if ($TimeEnd==NULL){
			$TimeEnd=now();	
		}
		$_SESSION['SearchTime']="and tdate>='".$TimeStart."' and tdate<='".$TimeEnd."'";	
	}else{
		$_SESSION['SearchTime']=NULL;		
	}
	if ($SearchContent!=NULL){
		if ($SearchType==1){
			#搜索会员编号
			$_SESSION['Search']="and nickname='".$SearchContent."'";
		}else if($SearchType==2){
			$_SESSION['Search']="and bdname='".$SearchContent."'";
		}
	}else{
		if ($SearchType==1){
			$_SESSION['Search']=NULL;
		}elseif($SearchType==2){
			#搜索未发放
			$_SESSION['Search']="and isgrant=0";
		}elseif($SearchType==3){
			#搜索已发放
			$_SESSION['Search']="and isgrant=1";
		}
	}
}else{
	if ($_GET['page']==NULL){
		$_SESSION['Search']=NULL;	
		$_SESSION['SearchTime']=NULL;
	}
}

#提现确认
if ($_POST['button']){
$cheuid_arr = $_POST['UID'];
	$tixian['isgrant']=1;
	foreach ((array)$cheuid_arr as $id)
	{	$ti=que_select_cl('tixian',$id);
		action::record("提现确认", $ti['uid'], $_SESSION['adminid'],"确认提现");
		
    	edit_update_cl('tixian',$tixian,$id);

    	$sqlll = "select * from member where id=".$ti['uid'];
    	$usss = getOne($sqlll);
    	if($usss){
            //通知 会员 打款成功
            $send->sendSms($systemparameters['access_key_id'],$systemparameters['access_key_secret'],$usss['userid'],'SMS_135800036','name',$usss['username']);
        }

	}
	echo "<script language=javascript>alert('提现确认完成.');window.location.href='?'</script>";
}

#删除记录
if ($_POST['button4']){
$cheuid_arr = $_POST['UID'];
	foreach ((array)$cheuid_arr as $id)
	{
		$tixian=que_select_cl('tixian',$id);
		$us=que_select_cl('member',$tixian['uid']);
		if($tixian['isgrant'] == 0){
		    if($tixian['txlx']==1){
                $xiugai['mey']=$us['mey']+$tixian['jine'];
            }else{
                    $xiugai['gwb']=$us['gwb']+$tixian['jine'];
            }
			action::record("删除提现记录", $tixian['uid'], $_SESSION['adminid'],"删除记录");
			edit_update_cl('member',$xiugai,$us['id']);
			edit_delete_cl('tixian',$id);
			echo "<script language=javascript>alert('删除完成.');window.location.href='?'</script>";
				
		}else{
			echo "<script>alert('已提现记录不能删除');</script>";
		}
    	
	}
}
//退提
if($_POST['button5']){
    $reson=$_POST['name'];
    $cheuid_arr = $_POST['id_list'];
    $cheuid=explode(",",$cheuid_arr);
    $tixian['isgrant']=2;
    $tixian['reson']=$reson;


    foreach ((array)$cheuid as $id)
    {
        $ti=que_select_cl('tixian',$id);
        $us=que_select_cl('member',$ti['uid']);
        if($ti['isgrant'] == 0||$ti['isgrant']==2){
            if($ti['txlx']==1){
                $xiugai['mey']=$us['mey']+$ti['jine'];
            //    tongbujine($ti['jine'],$us['usertel'],1);
            }else{
                    $xiugai['gwb']=$us['gwb']+$tixian['jine'];
            }
            edit_update_cl('member',$xiugai,$us['id']);
            edit_update_cl('tixian',$tixian,$id);
        }else{
            echo "<script>alert('已处理记录不能操作');</script>";
        }
    }

    echo "<script language=javascript>alert('提现处理成功.');window.location.href='?'</script>";
}

?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="css/table.css" rel="stylesheet" type="text/css">
<link href="css/style.css" rel="stylesheet" type="text/css">
    <link rel="stylesheet" href="//apps.bdimg.com/libs/jqueryui/1.10.4/css/jquery-ui.min.css">
    <script src="//apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script>
    <script src="//apps.bdimg.com/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
    <link rel="stylesheet" href="jqueryu i/style.css">
<script src="../js/calendar.js"></script>
    <link href="../layui-master/dist/css/layui.css" rel="stylesheet" type="text/css">
    <script src="../layui-master/dist/layui.js"></script>
<title>提现管理</title>
    <script>
        layui.use('laydate', function(){
            var laydate = layui.laydate;

            //执行一个laydate实例
            laydate.render({
                elem: '#TimeStart' //指定元素
            });
            laydate.render({
                elem: '#TimeEnd' //指定元素
            });
        });
    </script>
<SCRIPT LANGUAGE=javascript>
<!--
function SelectAll() {
	for (var i=0;i<document.form1.UID.length;i++) {
		var e=document.form1.UID[i];
		e.checked=!e.checked;
	}
}
-->
</script>
    <script>
        $(function() {

            $( "#dialog-form" ).dialog({
                autoOpen: false,
                height: 300,
                width: 350,
                modal: true,
            });
            $( "#button3" )
                .button()
                .click(function() {
                    var idList = [];
                    $(".id_checker").each(function (p1, p2, p3) {
                        if(this.checked){
                            idList.push($(this).val());
                        }

                    })
                    console.log(idList);
                    $("#id_list").val(idList);
                    $( "#dialog-form" ).dialog( "open" );
                });
        });
    </script>
<script language="javascript"> 
<!--     
//导出excel
function exportExcel(DivID){
  var oXL = new ActiveXObject("Excel.Application"); 
  var oWB = oXL.Workbooks.Add(); 
  var oSheet = oWB.ActiveSheet;  
  var sel=document.body.createTextRange();
  sel.moveToElementText(daochu);
  sel.select();
  sel.execCommand("Copy");
  oSheet.Paste();
  oXL.Visible = true;
}
-->
</script>
</head>
<body>
<div id="dialog-form" title="退提原因">
    <form action="?" method="post">
        <input type="hidden" name="id_list" id="id_list">
        <textarea name="name" id="name" class="text ui-widget-content ui-corner-all" cols ="20" rows="6"></textarea><br>
        <input type="submit" name="button5" class="layui-btn layui-btn-warm"  value="提交" >
    </form>
</div>
<form name="form1" method="post" action="?">
<table width="100%" cellpadding="3" cellspacing="0" border="0" align="center" class="layui-table" lay-skin="line">
      <tr>
        <td height="4" align="left">
          <select name="SearchType" id="SearchType">
            <option value="1">会员编号</option>
            <option value="4">服务中心</option>
            <option value="2">未发放</option>
            <option value="3">已发放</option>
          </select>
          <input type="text" name="SearchContent" id="SearchContent">
        <input type="submit" name="Search" id="Search" class="layui-btn layui-btn-small" value="搜索"></td>
        <td height="4" align="center"><input type="button" name="dayin" id="dayin" class="layui-btn layui-btn-small" value="导出表格" onClick="window.location.href='excel.php?table=tixian'"></td>
      </tr>
      <tr>
        <td height="5" colspan="2" align="left">搜索时间范围：
          <input type="text" name="TimeStart" id="TimeStart" style="width:100px" ">
          至
          <input type="text" name="TimeEnd" id="TimeEnd" style="width:100px" "></td>
      </tr>
      <tr><td colspan="2">
      <table width="100%" cellpadding="0" cellspacing="1" border="0" align="center" class="layui-table" lay-skin="line" id="daochu">
      <tr>
        <td height="10" colspan="15" align="center"> 提 现 管 理</td>
      </tr>
      <tr>
      	<td height="21" align="center"><input type="checkbox" name="checkbox" value="checkbox" onClick="javascript:SelectAll()"></td>
        <td align="center">会员编号</td>
        <td align="center">会员姓名</td>
        <td align="center">提现金额</td>
  <!--      <td align="center">税收</td>-->
<!--        <td align="center">手续费</td>-->
   <!--      <td align="center">爱心基金</td>-->
        <td align="center">实发金额</td>
        <td align="center">开户银行</td>
        <td align="center">开户帐号</td>
        <td align="center">开户姓名</td>
        <td align="center">开户地址</td>
        <td align="center">提现时间</td>
        <td align="center">服务中心</td>
        <td align="center">提现类型</td>
        <td align="center">审核状态</td>
        </tr>
      <?php
	  	$pagesize = 20; //设置每页记录数 
	  	$sql = "SELECT * FROM `tixian` WHERE 1=1 ".$_SESSION['Search']." ".$_SESSION['SearchTime']."";
		if($query = mysql_query($sql)){
	  		$sum = mysql_num_rows($query); //计算总记录数 
		}else{
			$sum=0;	
		} 
		if($sum % $pagesize == 0) //计算总页数 
			$total = (int)($sum/$pagesize); 
		else 
			$total = (int)($sum/$pagesize) + 1; 
			if (isset($_GET['page'])) //获得页码
			{ 
				$p = (int)$_GET['page'];
			} 
			else 
			{ 
				$p = 1;
			}
			if ($p>$total){
				$p=$total;	
			}
		$start = $pagesize * ($p - 1); //计算起始记录 
      	$sql = "SELECT * FROM `tixian` WHERE 1=1 ".$_SESSION['Search']." ".$_SESSION['SearchTime']." order by tdate desc limit ".$start.",".$pagesize;
		if($query = mysql_query($sql)){
		while ($row=mysql_fetch_array($query)){
	  ?>
      <tr>
      	<td height="21" align="center"><input type="checkbox" class="id_checker" name="UID[]"  id="UID" value="<?=$row['id']?>"></td>
        <td align="center"><?=$row['nickname']?></td>
        <td align="center"><?=$row['username']?></td>
        <td align="center"><?=$row['jine']?></td>
          <!--       <td align="center"><?/*=$row['glf']*/?></td>-->
<!--              <td align="center"><?/*=$row['shouxu']*/?></td>-->
    <!--      <td align="center"><?/*=$row['yingshi']*/?></td>-->
        <td align="center"><?=number_format($row['jine']-$row['shouxu'],2) ?></td>
        <td align="center"><?=$row['bankname']?></td>
        <td align="center"><?=$row['bankcard']?></td>
        <td align="center"><?=$row['bankusername']?></td>
        <td align="center"><?=$row['bankaddress']?></td>
        <td align="center"><?=$row['tdate']?></td>
        <td align="center"><?=$row['bdname']?></td>
        <td align="center"><?php if ($row['txlx']==1){  echo $tixianlx1; }else{ echo $tixianlx2; }?></td>
        <td align="center"><?php if ($row['isgrant']==1){?><font color="#FF0000">已发放</font><?php }elseif($row['isgrant']==0){?> <font color="#FF0000">未发放</font><?php }elseif($row['isgrant']==2){?><font color="#FF0000">未通过</font><?php }?></td>
      </tr>
      <?php
			}
		}
	  ?>
      </table>
      </td>
      </tr>
      <tr>
        <td height="21" colspan="2" align="right">
        <table width="100%" border="0">
          <tr>
            <td align="left"><input name="button" type="submit" class="layui-btn layui-btn-small" id="button" value="提现确认" onClick="{if(confirm('您确定要进行提现确认吗?')){this.document.selform.submit();return true;}return false;}">
            <input name="button4" type="submit" class="layui-btn layui-btn-radius layui-btn-danger" id="button4" value="删除记录" onClick="{if(confirm('您确定要删除该记录吗?')){this.document.selform.submit();return true;}return false;}">
                <input name="button" type="button" class="layui-btn layui-btn-warm" id="button3" value="退提" >

            <td align="right"><?php echo fenye($p,$pagesize,$sum,$total,$cx)?></td>
          </tr>
        </table></td>
      </tr>
    </table>
    </form>
</body>
</html>